<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>累加法</title>
</head>
<body>
 <script>
     var sum;
    var n=Number(prompt('请输入数字n的值'));
    sum=0;
    for(var i=2;i<=n;i++){
        sum+=(i-1)/i;
    }
    alert(sum+1);
 </script>
</body>
</html>